#include<iostream>
#include<map>

using namespace std;

int main(){
	int n;
	cin>>n;
	map<int,int> m;

	while(n--){
		int team_n,id,s;
		scanf("%d-%d %d",&team_n,&id,&s);
		m[team_n]+=s;
	}
	int max_i,max;
	for (auto i : m){
		// cout<<i.first<<" "<<i.second<<endl;
		if(i.second>max){
			max=i.second;
			max_i=i.first;
		}
	}
	cout<<max_i<<" "<<max<<endl;
}